<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${mapperPackage}.${mapperName}">

    <sql id="pageFrom">
        from ${table}
        <where>
            <#list columns as column>
            <#if column.javaType == "String">
            <if test="@com.liaoyifan.core.valid.Lang@isNotBlank(query.${column.javaName})">
                and ${column.columnName} like concat('%', <#noparse>#</#noparse>{query.${column.javaName}}, '%')
            </if>
            <#elseif column.javaType == "LocalDateTime" || column.javaType == "LocalDate">
            <if test="query.${column.javaName}.start != null">
                and ${column.columnName} >= <#noparse>#</#noparse>{query.${column.javaName}.start}
            </if>
            <if test="query.${column.javaName}.end != null">
                and ${column.columnName} &lt;= <#noparse>#</#noparse>{query.${column.javaName}.end}
            </if>
            <#else>
            <if test="query.${column.javaName} != null">
                and ${column.columnName} = <#noparse>#</#noparse>{query.${column.javaName}}
            </if>
            </#if>
            </#list>
        </where>
    </sql>

    <select id="pageList" resultType="${voPackage}.${voName}">
        select *
        <include refid="pageFrom"/>
        <#if hasIdColumn??>
        order by id desc
        </#if>
        <if test="query.start!=null">
            limit <#noparse>#</#noparse>{query.start},<#noparse>#</#noparse>{query.limit}
        </if>
    </select>

    <select id="pageCount" resultType="java.lang.Long">
        select count(*)
        <include refid="pageFrom"/>
    </select>

</mapper>
